package com.hfb.mashibing.alip8.designpattern._09observer;

import java.util.concurrent.TimeUnit;

/**
 * 题目：模拟 宝宝在睡觉，醒来后哭了，之后要喂奶
 * 面向对象的傻等，直到醒来
 */

public class V3 {

    public static void main(String[] args) throws InterruptedException {
        ChildV3 baby = new ChildV3();
        TimeUnit.SECONDS.sleep(3);
        // do something
        baby.wakeUp();

    }
}

class ChildV3 {
    private boolean cry = false;
    /*观察者在被观察者里面*/
    private DadV3 d = new DadV3();

    public ChildV3() {
        System.out.println("baby is doing sleepping !");
    }

    public boolean isCry() { return cry;}

    public void wakeUp(){
        cry = true;
        System.out.println("waked up! Crying! 555555555555555555");
        d.feed();
    }
}

/**
 * 加入观察者
 */
class DadV3 {
    public void feed() {
        System.out.println("he is Crying! dad is go to feed !");
    }
}
